from apps.common.base.serializers import *
from apps.merchant.coupon.models import *


class CouponBaseSerializer(BaseSerializer):
    class Meta:
        model = Coupon
        fields = "__all__"


class CouponModelSerializer(BaseSerializer):

    userModel = serializers.SerializerMethodField()
    def get_userModel(self, obj):
        try:
            return {'id': obj.user.id, 'code': obj.user.code, 'phone': obj.user.phone, 'nickname': obj.user.nickname}
        except:
            return {}
        
    user_code = serializers.SerializerMethodField()
    def get_user_code(self, obj):
        try:
            return obj.user.code
        except:
            return ''

    statusLabel = serializers.SerializerMethodField()
    def get_statusLabel(self, obj):
        try:
            return obj.get_status_display()
        except:
            return '未知'

    cancelTypeLabel = serializers.SerializerMethodField()
    def get_cancelTypeLabel(self, obj):
        try:
            return obj.get_cancelType_display()
        except:
            return '未知'

    typesLabel = serializers.SerializerMethodField()

    def get_typesLabel(self, obj):
        try:
            return obj.get_types_display()
        except:
            return '未知'

    weeksLabel = serializers.SerializerMethodField()

    def get_weeksLabel(self, obj):
        try:
            return obj.get_weeks_display()
        except:
            return '未知'

    timesLabel = serializers.SerializerMethodField()

    def get_timesLabel(self, obj):
        try:
            return obj.get_times_display()
        except:
            return '未知'

    class Meta:
        model = Coupon
        fields = "__all__"
